﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string password = textBox1.Text;
         
            if (password.Length < 8)
            {
                MessageBox.Show("密码不得小于8位！\n且只能是字母、数字和以下特殊字符的组合：\n~!@#$%^&*()_+|{}:<>?`-=\\[];',./\n请重新输入！");
                return;
            }
            
            string specialChars = "~!@#$%^&*()_+|{}:<>?`-=\\[];',./";
            foreach (char c in password)
            {
                if (!char.IsLetterOrDigit(c) && !specialChars.Contains(c))
                {
                    MessageBox.Show("密码不得小于8位！\n且只能是字母、数字和以下特殊字符的组合：\n~!@#$%^&*()_+|{}:<>?`-=\\[];',./\n请重新输入！");
                    return;
                }
            }
           
            int categoryCount = 0;
            bool hasLower = false, hasUpper = false, hasDigit = false, hasSpecial = false;
            foreach (char c in password)
            {
                if (char.IsLower(c))
                {
                    hasLower = true;
                }
                else if (char.IsUpper(c))
                {
                    hasUpper = true;
                }
                else if (char.IsDigit(c))
                {
                    hasDigit = true;
                }
                else if (specialChars.Contains(c))
                {
                    hasSpecial = true;
                }
            }
            if (hasLower) categoryCount++;
            if (hasUpper) categoryCount++;
            if (hasDigit) categoryCount++;
            if (hasSpecial) categoryCount++;
         
            string strength = "";
            
            if (categoryCount == 4)
            {
                strength = "强";
            }
            else if (categoryCount == 3)
            {
                strength = "较强";
            }
            else if (categoryCount == 2)
            {
                strength = "较弱";
            }
            else
            {
                strength = "弱";
            }
            MessageBox.Show("密码强度：" + strength);
        }
    }
}